
--add weapon to list of MckaysEnts MUST BE FIRST
MckaysPack:CreateEnt("Ancient Gun")

--################### Head
SWEP.Category = "Stargate";
SWEP.PrintName = "Ancient Gun";
SWEP.Author = "aVoN edited by Dr.Mckay";
SWEP.Contact = "Steam:Dr.Mckay or Zman115";
SWEP.Purpose = "Kill Wraith";
SWEP.Instructions = "Aim, Fire 'Oh ya got another Wraith'";
SWEP.Pack = "Mckay's Stargate Pack";
SWEP.Base = "weapon_base";		
SWEP.Slot = 1;
SWEP.SlotPos = 3;
SWEP.DrawAmmo	= true;
SWEP.DrawCrosshair = true;

if StarGate.CFG:Get("Ancient_Gun","Model",1) == 1 then
	SWEP.ViewModel = "models/micropro/asuragun/v_asugun/v_asugun.mdl";	
	SWEP.WorldModel = "models/micropro/asuragun/w_asugun/w_asugun.mdl";
else
	SWEP.ViewModel = "models/micropro/ancientstunner/v_ancientstunner/v_ancientstunner.mdl"
	SWEP.WorldModel = "models/micropro/ancientstunner/w_ancientstunner/w_ancientstunner.mdl"
end
-- primary.
SWEP.Primary.ClipSize = StarGate.CFG:Get("Ancient_Gun","Round",16);	-- remember to change on reload below
SWEP.Primary.DefaultClip = StarGate.CFG:Get("Ancient_Gun","Round",16); -- at least clip size
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo	= "StriderMinigun";

-- secondary
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = "none";

-- spawnables.
SWEP.Spawnable = true;
SWEP.AdminSpawnable = false;


local ReloadTime = 0;
local reloading = false;

-- Add weapon for NPCs
list.Set("NPCWeapons","weapon_ancient","Ancient Gun");

--################### Deploy @aVoN
function SWEP:Deploy()
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW); -- Animation
	if SERVER then self.Owner:EmitSound(self.Sounds.Deploy,90) end;
end

function SWEP:Reload() --Fix / Stop timer error upon death!
	if not reloading then
			if(self.Weapon:Clip1() <= 0) then
				timer.Simple(MckaysPack.Ents.AncientGun.ChargeTime,function() MckaysPack.Ents.AncientGun:ReloadEnergy(self.Weapon, self.Owner, self.Sounds.Deploy) end)
				reloading = true 
				end;
	end
end

function MckaysPack.Ents.AncientGun:ReloadEnergy(weapon, owner, sounds)
		weapon:SetClip1( MckaysPack.Ents.AncientGun.Round )
		reloading = false;
		if SERVER then owner:EmitSound(sounds ,90) end;
end

--################### Shoot @aVoN
function SWEP:PrimaryAttack()	
	if(not ValidEntity(self.Owner)) then return end;
	if ( !self:CanPrimaryAttack() ) then return end
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK);
	
	-- Muzzle
	local fx = EffectData();
	fx:SetScale(0);
	fx:SetOrigin(self.Owner:GetShootPos());
	fx:SetEntity(self.Owner);
	fx:SetRadius(48);
	util.Effect("energy_muzzle",fx,true);
	-- Shot
	if SERVER then self:SVPrimaryAttack() end;
	if (self.Weapon:Clip1() <= 0) then self.Weapon:Reload() end
	self.Weapon:SetNextPrimaryFire(CurTime()+0.2);
	return true;
end

--Is none atm :D
function SWEP:SecondaryAttack()
	return false;
end

--Custom ammo display
--[[function SWEP:CustomAmmoDisplay()
	self.AmmoDisplay = self.AmmoDisplay or {}
		
	self.AmmoDisplay.Draw = true
		
	if self.primary.ClipSize > 0 then
		self.AmmoDisplay.PrimaryClip = self.Weapon:Clip1()
		self.AmmoDisplay.PrimaryAmmo = self:Ammo1()
	end
	if self.Secondary.ClipSize > 0 then
		self.AmmoDisplay.SecondaryClip = self.Weapon:Clip2()
		self.AmmoDisplay.SecondaryAmmo = self:Ammo2()
	end
	
	return self.AmmoDisplay
end]]--